package com.choudou5.solr.web;

import com.choudou5.solr.framework.util.RequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * @name 基础 Servlet
 * @author choudou5
 * @date 2018-08-06
 */
public class AbsBaseServlet extends HttpServlet {

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    protected void printlnJVMInfo(HttpServletRequest req){
        // 打印JVM信息。
        if (logger.isDebugEnabled()){
            long endTime = System.currentTimeMillis(); 	//2、结束时间
            logger.debug("URI: {}  最大内存: {}m  已分配内存: {}m  已分配内存中的剩余空间: {}m  最大可用内存: {}m",
                    RequestUtil.getReqUrl(req), Runtime.getRuntime().maxMemory()/1024/1024, Runtime.getRuntime().totalMemory()/1024/1024, Runtime.getRuntime().freeMemory()/1024/1024,
                    (Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory())/1024/1024);
        }
    }

}
